//
//  ResgisterSecurityPwdVC.m
//  PrivateSteward
//
//  Created by lanou3g on 16/4/5.
//  Copyright © 2016年 闫贺晨. All rights reserved.
//

#import "ResgisterSecurityPwdVC.h"
#import "UnloginPersonalHomePageVC.h"

@interface ResgisterSecurityPwdVC ()<UITextFieldDelegate>

@end

@implementation ResgisterSecurityPwdVC

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationItem.hidesBackButton = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)FinishButton:(UIButton *)sender {
    
    AVQuery *query = [AVQuery queryWithClassName:@"UserClass"];
    [query whereKey:@"phonrNumber" equalTo:[[AVUser currentUser] username]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (objects.count > 0) {
            AVObject *obj = [AVObject objectWithoutDataWithClassName:@"UserClass" objectId:[objects[0] objectId]];
            [obj setObject:self.SecurityTextFiled.text forKey:@"securityPwd"];
            [obj saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (succeeded) {
                    [self alertAction:@"成功" messageString:@"安全密码设置成功,请到主页面进行登录"];
                }
                else
                {  [self alertAction:@"失败" messageString:@"请重新输入"];
                }
            }];
        }
        
    }];

}
-(void)alertAction:(NSString *)alertstring messageString:(NSString *)messageString
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:alertstring message:messageString preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        if ([alertstring isEqualToString:@"成功"]) {
            UnloginPersonalHomePageVC *unloginVC = [[UnloginPersonalHomePageVC alloc]init];
            [self.navigationController pushViewController:unloginVC animated:YES];
        }
    }];
    
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:^{
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
